import java.util.Scanner;

public class IncreasingSequence {
    static int a = 30, b = 50;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[][] nums = new char[a][b];
        for (int i = 0; i < a; i++) {
            nums[i] = sc.next().toCharArray();
        }
        int count = 0;
        for (int i = 0; i < a; i++) {
            for (int j = 0; j < b; j++) {
                count += count(i, j, nums);
            }
        }
        System.out.println(count);
    }

    // 从左向右看是递增的 或者 从上向下看是递增的
    public static int count(int i, int j, char[][] nums) {
        int count = 0;
        // 竖着看
        for (int k = i + 1; k < a; k++) {
            if (nums[k][j] > nums[i][j]) {
                System.out.println(nums[i][j] + " " + nums[k][j]);
                count ++;
            }
        }
        // 横着看
        for (int k = j + 1; k < b; k++) {
            if (nums[i][k] > nums[i][j]) {
                System.out.println(nums[i][j] + " " + nums[i][k]);
                count ++;
            }
        }
        // 正45度角
        int index = j;
        for (int k = i + 1; k < Math.min(a, b); k++) {
            if (index + 1 < b) {
                if (nums[k][++index] > nums[i][j]) {
                    System.out.println(nums[i][j] + " " + nums[k][index]);
                    count ++;
                }
            }
        }
        // 负45度
        index = j;
        for (int k = i + 1; k < a; k++) {
            if (index - 1 >= 0) {
                if (nums[k][--index] != nums[i][j]) {
                    System.out.println(nums[k][index] + " " + nums[i][j]);
                    count ++;
                }
            }
        }
        return count;
    }
}
